%% Load the data - Select the File: 'ViscosityProfiles'
close all; clear all; clc;
PerPEO = '0.5'
%%
close all;clc;
start = 4;
fin = 10;
PerPEOColor = [1 1 1;               % Control 
                0.635 0.078 0.184;  % 0.05 % PEO
                0.588 0.286 0.612;  % 0.1% PEO
                0.929 0.694 0.125;  % 0.25% PEO
                0.466 0.674 0.188;  % 0.5% PEO
                0.85 0.325 0.0980]; % 0.82% PEO

if strcmp(PerPEO,'0.1')
    load('.\ViscosityProfiles\0pt1PEO')
    vis = cell2mat(mu');
    ViscColor = PerPEOColor(3,:);
    x = xPos + (500 - median(xPos));
elseif strcmp(PerPEO,'0.25')
    load('.\ViscosityProfiles\0pt25PEO')
    vis = cell2mat(mu');
    ViscColor = PerPEOColor(4,:);
    x = xPos + (500 - median(xPos));
elseif strcmp(PerPEO,'0.5')
    load('.\ViscosityProfiles\0pt5PEO')
    vis = cell2mat(mu');
    ViscColor = PerPEOColor(5,:);
    x = xPos + (500 - median(xPos));
elseif strcmp(PerPEO,'0.82')
    load('.\ViscosityProfiles\0pt82PEO')
    vis = cell2mat(mu');
    ViscColor = PerPEOColor(6,:);
    x = xPos + (500 - median(xPos));
else
    load('.\ViscosityProfiles\0pt0PEO')
    vis = cell2mat(mu');
    ViscColor = [0 0 0];
    start = 1; fin = 5;
    x = xPos + (500 - median(xPos));
end

close all;clc;
MeanVis = mean(vis(start:fin,:)); STDVisc = std(vis(start:fin,:));
Marker = '-';
FillColor = ViscColor; LineColor = ViscColor; 
LineWidth = 1; alpha_gradient = 0.8; alpha_errorbar = 0.50;
mypapersize = [.9 .9]; alw = 0.5;

y = MeanVis; y_max = 6.2;
error = STDVisc;
ticks_y = [0,25,50,75,100];

SingleVisc = figure('color',[1 1 1]);
    plot(x,MeanVis,'color',ViscColor)
    hold on;
    patch = fill([x,fliplr(x)],[y + error,fliplr(y - error)],FillColor);
    set(patch, 'edgecolor', 'none'); set(patch, 'FaceAlpha', alpha_errorbar);
    plot(x,y,Marker,'Color',LineColor,'MarkerEdgeColor',LineColor,'LineWidth',LineWidth)
    xlim([0 1000]); ylim([0 y_max]);
    xticks([0 250 500 750 1000]); xticklabels({'','','','',''});    
    yticks([0 2 4 6]); xticklabels({'','','','',''});
    set(gca,'LineWidth',alw); set(gca,'XColor',[0 0 0]);set(gca,'YColor',[0 0 0]);
    
    set(gcf, 'PaperUnits', 'inches', 'papersize', mypapersize, 'PaperPosition', [0 0 mypapersize]);
    set(SingleVisc,'Units','inches','Position',[0 0 mypapersize]);    
    
    ax = gca;outerpos = ax.OuterPosition;ti = ax.TightInset;
    left = outerpos(1);bottom = outerpos(2);ax_width = outerpos(3);ax_height = outerpos(4);
    ax.Position = [left+0.011 bottom+0.01 ax_width-0.025 ax_height-0.022] ;
% Save Figure
    figdir = '.\Figure1\ViscosityProfile';
    print(SingleVisc, '-painters','-dpdf', '-r1200', [figdir,'\Visc_',PerPEO,'.pdf']);
    
% Save Data in Excel
dir_Excel = '.\Source data\MainText';
if strcmp(PerPEO,'0.1'); column1 = 'E4'; column2 = 'F4'; column3 = 'G4';
    elseif strcmp(PerPEO,'0.25'); column1 = 'I4'; column2 = 'J4'; column3 = 'K4';
    elseif strcmp(PerPEO,'0.5'); column1 = 'M4'; column2 = 'N4'; column3 = 'O4';
    elseif strcmp(PerPEO,'0.82'); column1 = 'Q4'; column2 = 'R4'; column3 = 'S4';
    else; column1 = 'A4'; column2 = 'B4'; column3 = 'C4';
end
writematrix(x',[dir_Excel,'Figure1.xlsx'],'Sheet',7,'Range',column1)
writematrix(MeanVis',[dir_Excel,'Figure1.xlsx'],'Sheet',7,'Range',column2)
writematrix(error',[dir_Excel,'Figure1.xlsx'],'Sheet',7,'Range',column3)
    